package com.xiaobias.mySwitch;

/**
 * 案例一
 */
public class Switch001 {

    public static void main(String[] args) {
        before();
        after();
    }

    public static void before () {
        String name = "许庶";
        String alias = null;
        switch(name) {
            case "许庶":
                alias = "元直";
                break;
            case "周瑜":
                alias = "公瑾";
                break;
            case "项羽":
                alias = "楚霸王";
                break;
            case "刘邦":
                alias = "汉高祖";
                break;
            default:
                alias = "未知";
                break;
        }
        System.out.println("alias: " + alias);
    }

    public static void after() {
        var name = "许庶";
        String alias = switch (name) {
            case "周瑜" -> "公瑾";
            case "许庶" -> "元直";
            case "项羽" -> "楚霸王";
            case "刘邦" -> "汉高祖";
            default -> "未知";
        };
        System.out.println("alias: " + alias);
    }
}
